/* eslint-disable no-use-before-define */
import React, { Component } from 'react'
import bg from './back.jpg'
export default class Com1 extends Component {
  constructor (props) {
    super(props)
    this.state = {
      x: 0,
      y: 0
    }
  }

  fn = (e) => {
    this.setState({
      x: e.pageX,
      y: e.pageY
    })
  }

  componentDidMount () {
    // 添加鼠标事件
    window.addEventListener('mousemove', this.fn)
  }

  componentWillUnmount () {
    window.removeEventListener('mousemove', this.fn)
  }

  render () {
    return (
      <div><img src={bg} style={{ top: this.state.y, left: this.state.x, position: 'absolute', width: 50 }} /></div>

    )
  }
}
